package cn.edu.bzu.ie.sf.mealsmisweb.mapper;

import cn.edu.bzu.ie.sf.mealsmisweb.entity.ApkVersion;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

/**
 * 版本信息Mapper接口
 * @author  宋锋
 * @date 2019-03-22 14:22
 */
@Repository
public interface ApkVersionMapper extends Mapper<ApkVersion> {
    //查询最新一条记录信息
    @Select("select * from apkVersion where id=1")
    ApkVersion getTop1ApkVersion();

    // 更新版本信息
    @UpdateProvider(type = ApkVersionDaoProvider.class, method = "updateTop1ApkVersion")
    int updateTop1ApkVersion(ApkVersion obj);

    class ApkVersionDaoProvider {   //内容自定义的查询类
        public String updateTop1ApkVersion(ApkVersion obj) {
            String sql = "update apkVersion ";
            String strSet = "";
            if(obj.getVersionCode()!=null){
                strSet += " set versionCode = #{obj.getVersionCode()} ";
            }
            if(obj.getVersionName()!=null){
                if(strSet.length()==0) {   //为空的话
                    strSet += " set versionName = #{obj.getVersionName()}";
                }else{    //不为空
                    strSet += ", versionName = #{obj.getVersionName()}";
                }
            }
            if(obj.getEditDt()!=null){
                if(strSet.length()==0) {   //为空的话
                    strSet += " set editDt = #{obj.getEditDt()}";
                }else{    //不为空
                    strSet += ",  editDt = #{obj.getEditDt()}";
                }
            }
            sql = sql + strSet + " where id=#{obj.getId}";
            return sql;
        }
    }
}
